home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / '92_HACK / CHANGE_T / GENERIC_.C next >
Text File  |  1991-06-05  |  3KB  |  115 lines

  1. #define OKButton    1
  2.  
  3. /************************************************************************
  4.  *
  5.  *  Function:        OutlineOK
  6.  *
  7.  *  Purpose:        outline the OK button in a dialog
  8.  *
  9.  *  Returns:        nothing
  10.  *
  11.  *  Side Effects:    standard box is drawn around OK button
  12.  *
  13.  *  Description:    draws the heavy rounded box around the OK button,
  14.  *                    so that the user knows that hitting enter or return
  15.  *                    is the same as pressing the OK button.  OK is assumed
  16.  *                    to be the first item in the dialog.
  17.  *
  18.  ************************************************************************/
  19. void
  20. OutlineOK(dPtr)
  21. DialogPtr dPtr;
  22. {
  23.     int unusedItemType;
  24.     Handle unusedItemHandle;
  25.     Rect box;
  26.     PenState p;
  27.     GrafPtr    savedPort;
  28.  
  29.     /*    This next little piece of code puts the default heavy rounded
  30.         box around the "OK" button, so the user knows that pressing
  31.         return is the same as hitting "OK"
  32.     */
  33.     GetPort(&savedPort);
  34.     SetPort(dPtr);        /* without this, can't highlite OK */
  35.     GetDItem(dPtr, OKButton, &unusedItemType, &unusedItemHandle, &box);
  36.     GetPenState(&p);
  37.     PenSize(3,3);
  38.     InsetRect(&box, -4, -4);
  39.     FrameRoundRect(&box, 16, 16);
  40.     PenSize(p.pnSize.h, p.pnSize.v);
  41.     SetPort(savedPort);
  42. }
  43.  
  44.  
  45. /************************************************************************
  46.  *
  47.  *  Function:        GenericFilter
  48.  *
  49.  *    Purpose:        generic dialog filter
  50.  *
  51.  *    Returns:        true if nothing has happened, false if a choice has
  52.  *                    been made.  itemHit is modified to return the value
  53.  *                    of the item selected.
  54.  *
  55.  *    Side Effects:    Handles cut, copy, paste, cancel for system 6.
  56.  *
  57.  *    Description:    You'll get either an updateEvt, a keyDown, or an 
  58.  *                    autoKey.  On updateEvt, handle window updates and
  59.  *                    if necessary, draw the OK outline.  If a keydown (or
  60.  *                    autokey) handle the key as apporpriate.
  61.  *
  62.  ************************************************************************/
  63. pascal Boolean GenericFilter(DialogPtr theDialog,EventRecord *theEvent,short *itemHit)
  64. {
  65.    WindowPtr updateWindow;
  66.    char theChar;
  67.  
  68.    switch (theEvent->what) {
  69.        case updateEvt:
  70.            updateWindow = (WindowPtr) theEvent->message;
  71.            if (updateWindow!=theDialog)
  72.                HandleUpdates(updateWindow);    /* <<<----- call window updates here */
  73.            else
  74.                OutlineOK(theDialog);   /*  <<<--- I draw ok outline here */
  75.            break;
  76.        case keyDown:
  77.        case autoKey:
  78.            theChar = theEvent->message & charCodeMask;
  79.            if ((theEvent->modifiers & cmdKey) != 0) {
  80.                switch (theChar) {
  81.                case 'x':
  82.                    DlgCut(theDialog);
  83.                    *itemHit = 0;
  84.                    return true;
  85.                case 'c':
  86.                    DlgCopy(theDialog);
  87.                    *itemHit = 0;
  88.                    return true;
  89.                case 'v':
  90.                    DlgPaste(theDialog);
  91.                    *itemHit = 0;
  92.                    return true;
  93.                case '.':
  94.                    *itemHit = Cancel;
  95.                    return true;
  96.                default:
  97.                    return false;
  98.                break;
  99.                }
  100.            }
  101.            else switch (theChar) {
  102.                case 0x0d:  /* CR */
  103.                case 0x03:  /* enter */
  104.                    *itemHit = OK;
  105.                    return true;
  106.                case 0x1b:  /* ESC */
  107.                    *itemHit = Cancel;
  108.                return true;
  109.            }
  110.            break;
  111.        }
  112.    return false;
  113. }
  114.  
  115.